package com.qhsx.asset.controller;

import com.qhsx.asset.domain.AssetProduct;
import com.qhsx.asset.service.IAssetProductService;
import com.qhsx.common.annotation.DataScope;
import com.qhsx.common.core.controller.BaseController;
import com.qhsx.common.core.domain.AjaxResult;
import com.qhsx.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 耗材领用Controller
 *
 * @author yepanpan
 * @date 2021-03-05
 */
@RestController
@RequestMapping("/asset/product")
@Api("产品相关")
public class AssetProductController extends BaseController
{
    @Autowired
    private IAssetProductService assetProductService;


    @GetMapping("/list")
    @ApiOperation("列表")
    @DataScope(userAlias = "au", deptAlias = "au")
    public TableDataInfo list(AssetProduct assetProduct)
    {
        startPage();
        List<AssetProduct> list = assetProductService.list(assetProduct);
        return getDataTable(list);
    }

    @GetMapping("init")
    @ApiOperation("初始化数据")
    AjaxResult  initBatch(){
        assetProductService.initBatch();
        return toAjax(1);
    }

    @PostMapping("leave")
    @ApiOperation("出库")
    AjaxResult  leave(@RequestBody Map<String,String> params){
        assetProductService.leave(params.get("handle"));
        return toAjax(1);
    }

    @GetMapping("id")
    @ApiOperation("获取id")
    AjaxResult id(String handle){
        String handle1=handle.substring(handle.indexOf("86.122"));
        return  AjaxResult.success("成功",assetProductService.id(handle1));
    }


}
